/**
 * Copyright 2011 Aaron Zeckoski
 * This file is part of Maven Exercise 8.
 *
 * Maven Exercise 8 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Maven Exercise 8 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Maven Exercise 8.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.az;

import org.apache.commons.lang.StringUtils;
import org.az.dao.CommentsDAO;
import org.az.dao.entity.CommentsEntity;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * This is a sample java file
 * 
 * @author Aaron Zeckoski (azeckoski @ vt.edu)
 */
@Component
public class Sample {

    private static final Logger log = LoggerFactory.getLogger(Sample.class);

    public static CommentsDAO dao;

    /**
     * Load up the dao using spring autowiring
     * @param instance
     */
    @Autowired(required = true)
    Sample(CommentsDAO instance) {
        dao = instance;
        log.info("spring wired up dao");
    }

    public static String trimLower(String input) {
        String s = StringUtils.trimToEmpty(input);
        return StringUtils.lowerCase(s);
    }

    public static String storeComment() {
        log.info("storing comment");
        CommentsEntity ce = dao.save( new CommentsEntity( new DateTime().toString() ) );
        return ce.getId().toString();
    }

}
